// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2004-7-13

#ifndef __MEMPOOL_H_COMMON_BASE__
#define __MEMPOOL_H_COMMON_BASE__

#pragma once

//##ModelId=44C4B5F70196
class CJoyMemPool
{
protected:
	//##ModelId=44C4B5F701E8
    class CBlock
    {
    public:
        union
        {
            CBlock*     m_pNext;
            CBlock**    m_ppHead;
        };
    };
	//##ModelId=44C4B5F701F4
    class CGroup
    {
    public:
		//##ModelId=44C4B5F701F8
        CGroup* m_pNext;
    };
protected:
	//##ModelId=44C4B5F70197
    int m_nBlockStepShift;
	//##ModelId=44C4B5F70198
    int m_nBlockStep;
	//##ModelId=44C4B5F701A5
    int m_nStepCount;
	//##ModelId=44C4B5F701B5
    int m_nGroupSize;
	//##ModelId=44C4B5F701B6
    int m_nMaxAllocSize;

	//##ModelId=44C4B5F701B7
    int m_nMemTotal;
	//##ModelId=44C4B5F701C5
    int m_nMemUsing;
	//##ModelId=44C4B5F701C7
    CBlock** m_ppHeadBlocks;
	//##ModelId=44C4B5F701CC
    CGroup*  m_pGroups;
public:
	//##ModelId=44C4B5F701D4
    CJoyMemPool(int nBlockStep, int nStepCount, int nGroupSize);
	//##ModelId=44C4B5F701D8
    virtual ~CJoyMemPool(void);

	//##ModelId=44C4B5F701E4
    void* Alloc(size_t nSize);
	//##ModelId=44C4B5F701E6
    void Free(void* pMem);
};

//##ModelId=44C4B5F70203
class CJoyBlockPool
{
protected:
    //class CBlock
public:
};

#ifdef _DEBUG
#define JOY_DISABLE_POOL
#endif

//##ModelId=44C4B5F70204
class CJoyPoolObject
{
public:
#ifndef JOY_DISABLE_POOL
#pragma push_macro("new")
#undef new
	//##ModelId=44C4B5F70213
    static void* Alloc(size_t s);
	//##ModelId=44C4B5F70216
    static void Free(void* p);
	//##ModelId=44C4B5F70219
    void* operator new (size_t s)
    {
        return Alloc(s);
    }
	//##ModelId=44C4B5F70222
    void* operator new (size_t s, PCSTR fileName, int nLine)
    {
        fileName;nLine;
        return Alloc(s);
    }
	//##ModelId=44C4B5F70226
    void operator delete (void* p)
    {
        Free(p);
    }
#pragma pop_macro("new")
#endif
};

#endif  // __MEMPOOL_H_COMMON_BASE__
